package Text7;
import java.util.*;
public class Main {
    public static int N = 510,M = 10010,n,m,k,max = 0x3f3f3f3f;
    public static int[] dist = new int[N];//从一号点到n号点的距离
    public static int[] back = new int[N];//备份数组从一号点到n号点的距离
    public static edg[] edgs = new edg[M];

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        k = scanner.nextInt();
        Arrays.fill(dist,max);
        dist[1]=0;
        for (int i = 0; i < m; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int c = scanner.nextInt();
            edgs[i]= new edg(a, b, c);
        }
        bellman_ford();
    }

    private static void bellman_ford() {
        for (int i = 0; i < k; i++) {
            back=Arrays.copyOf(dist,n+1);
            for (int j = 0; j < m; j++) {
                edg e=edgs[j];
                int a=e.a,b=e.b,c=e.c;
                if(dist[b]>back[a]+c){
                    dist[b]=back[a]+c;
                }
            }
        }
        if(dist[n] > max / 2) System.out.println("impossible");
        else System.out.println(dist[n]);
    }
}

class edg{
    int a;
    int b;
    int c;

    public edg(int a, int b, int c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }
}
